
<template>
    <h2>显示页面</h2>
    名称:<input type="text" v-model="Name" id="Name">
    投资区间:<input type="text" v-model="All_1" id="All_1">
    -<input type="text" v-model="All_2" id="All_2">
    <input type="button" value="查询" @click="Showss" />
    <table>
        <thead>
            <tr>
                <td>编号</td>
                <td>投资名称</td>
                <td>总金额</td>
                <td>已投</td>
                <td>剩余</td>
                <td>人数</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in data" :key="item.Id">
                <td>{{ item.Id }}</td>
                <td>{{ item.Name }}</td>
                <td>{{ item.Alls }}</td>
                <td>{{ item.Back }}</td>
                <td>{{ item.Receive }}</td>
                <td>{{ item.Num }}</td>
                <td>
                    <input type="button" value="删除" @click="Del(item.Id)">
                    <input type="button" value="修改" @click="Upa(item.Id)">
                </td>
            </tr>


        </tbody>
    </table>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import { onMounted } from "vue";

const data = ref([{
    Id: 0,
    Name: '',
    Alls: 0,
    Back: 0,
    Id: 0

}])
onMounted(() => {
    axios.get('http://localhost:31285/api/Demo/Show'

    )
        .then(res => {
            data.value = res.data;
        })
        .catch(error => {
            console.log(error);
        })
})
const Showss = () => {
    axios.get('http://localhost:31285/api/Demo/Showss', {
        params: {
            Name: Name.value,
            All_1: All_1.value,
            All_2: All_2.value,
        }
    })
        .then(res => {
            data.value = res.data;

        })
        .catch(error => {
            console.log(error);
        })
}
const Del = (Id: number) => {
    if (confirm("确定要删除吗?")) {
        axios.get('http://localhost:31285/api/Demo/Del', {
            params: {
                Id: Id
            }
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    Showss();
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
    }




}

const router = useRouter();
const Upa = (Id: number) => {
    router.push({
        name: 'Update',
        params: {
            Id: Id
        }
    })
}

</script>